<?php

namespace app\activity\controller;

use library\Controller;


/** 活动类型类型
 * Created by PhpStorm.
 * User: ycp
 * Date: 2019/11/18
 * Time: 21:07
 */

class Type extends Controller
{
    protected $table = 'lite_app_sports_type';

    //活动类型首页
    public function index()
    {
        $this->activity_id = $this->request->param('activity_id');
        $activityName = db($this->activityTable)->where(['id' => $this->activity_id])->value('name');
        $this->title = $activityName. '组别管理';
        $where = ['is_deleted' => '0', 'activity_id' =>  $this->activity_id];
        $this->statusTitle = ['0' => '未开始', '1' => '进行中', '2' => '已结束'];
        $this->_query($this->table)->like('name')->where($where)->page();
    }

    //添加活动类型
    public function add()
    {
        $this->activity_id = $this->request->param('activity_id');
        $this->title = '添加组别';
        $cateData = db("lite_article_cate")->where(['is_deleted' => 0])->select();
        $this->cateData = $cateData;
        $this->isAddMode = '1';
        $this->applyCsrfToken();
        return $this->_form($this->table, 'form');
    }

    public function edit()
    {
        $this->title = '编辑组别';
        $this->activity_id = $this->request->param('activity_id');
        $cateData = db("lite_article_cate")->where(['is_deleted' => 0])->select();
        $this->cateData = $cateData;
        $this->isAddMode = '0';
        $this->applyCsrfToken();
        return $this->_form($this->table, 'form');
    }

    /**
     * 表单结果处理
     * @param boolean $result
     */
    protected function _form_result($result)
    {
        if ($result && $this->request->isPost()) {
            $this->success('组别编辑成功！', 'javascript:history.back()');
        }
    }

    public function del()
    {
        $this->applyCsrfToken();
        $this->_delete($this->table);
    }


    public function _form_filter(&$data)
    {
        if ($this->request->isGet()) {
        } elseif ($this->request->isPost()) {
            $data['create_time'] = date('Y-m-d H:i:s');
        }
    }

}